package com.blb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;

@RestController
@EnableConfigServer
@SpringBootApplication
public class NoteConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(NoteConfigApplication.class, args);
    }

    @PostMapping("refresh")
    public void refresh() throws URISyntaxException {
        RestTemplate restTemplate = new RestTemplate();
        RequestEntity<Void> responseEntity=null;

        try{
            responseEntity = RequestEntity
                    .post(new URI("http://localhost:9090/actuator/bus-refresh"))
                    .contentType(MediaType.APPLICATION_JSON).build();
        }catch (URISyntaxException e){
            e.printStackTrace();
        }
        restTemplate.exchange(responseEntity,String.class);
    }
}
